package com.kichina.galaxy.dev.tools.excel.poi.read;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;

import java.io.FileInputStream;

/**
 * @author Surging
 * @version 1.0
 * @ClassName ExcelReadTest
 * @date 2022/5/26 0:14
 * @desc
 */
public class ExcelReadTest {

    String PATH = "D:\\project\\personal\\Java\\meta_mall\\a测试文档\\poi\\";

    /*
     * @Author Surging
     * @Description 03版本xls处理 最大行65325 Excel读取
     * @Param
     * @Return void
     * @Date  2022/5/25 20:58
     **/
    @Test
    public void readTest03() throws Exception {
        FileInputStream fis = new FileInputStream(PATH + "Excel测试写入03.xls");
//        FileOutputStream fos = new FileOutputStream(PATH+"Excel测试写入");
        //获取一个工作簿
        Workbook wb = new HSSFWorkbook(fis);
        //获取一个工作表
        Sheet sheet = wb.getSheetAt(0);
        //获取一行
        Row row = sheet.getRow(0);
        //获取单元格
        Cell cell = row.getCell(0);
        System.out.println(cell.getStringCellValue());
        //关闭流
        fis.close();
    }

    /*
     * @Author Surging
     * @Description 07版本xlsx处理 Excel读取
     * @Param
     * @Return void
     * @Date  2022/5/25 20:58
     **/
    @Test
    public void readTest07() throws Exception {
        FileInputStream fis = new FileInputStream(PATH + "Excel测试写入07.xlsx");
//        FileOutputStream fos = new FileOutputStream(PATH+"Excel测试写入");
        //获取一个工作簿
        Workbook wb = new XSSFWorkbook(fis);
        int numberOfSheets = wb.getNumberOfSheets();
        //获取一个工作表
        Sheet sheet = wb.getSheetAt(0);
        int physicalNumberOfRows = sheet.getPhysicalNumberOfRows();
        //获取一行
        Row row = sheet.getRow(0);
        int physicalNumberOfCells = row.getPhysicalNumberOfCells();
        //获取单元格
        Cell cell = row.getCell(0);
        System.out.println(cell.getStringCellValue() + "有多少个工作簿" + numberOfSheets+ "有多少行" + physicalNumberOfRows + "有多少列" + physicalNumberOfCells);
        //关闭流
        fis.close();
    }
}
